完成了大概80%的功能之後,我們還剩下機房的服務資訊列表沒完成,
我們要去取得這機房內有幾台電腦等相關數據,
首先在message.py之中新增,
class roomResourceslable():
def returna(self):
computerdata = []
for data in RoomInformationdata.find():
computerdata = data
flex_message = FlexSendMessage(
alt_text='hello',
contents={
"type": "bubble",
"size": "mega",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "機房資源列表",
"color": "#ffffff",
"size": "xl",
"flex": 4,
"weight": "regular",
"margin": "xs"
}
]
}
],
"paddingAll": "20px",
"backgroundColor": "#0367D3",
"spacing": "md",
"height": "80px",
"paddingTop": "22px"
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "VCPU數量(顆):"+ str(computerdata["vcpu"]),
"color": "#0367D3"
},
{
"type": "text",
"text": "RAM數量(GB):"+ str(computerdata["ram"]),
"color": "#0367D3"
},
{
"type": "text",
"text": "機房儲存空間(TB):"+str(computerdata["disk"]),
"color": "#0367D3"
},
{
"type": "text",
"text": "機房Switch數量(台):"+str(computerdata["switch"]),
"color": "#0367D3"
},
{
"type": "text",
"text": "機房SDN Switch 數量(台):"+str(computerdata["sdnSwitch"]),
"color": "#0367D3"
},
{
"type": "text",
"text": "機房一般主機數量(台):"+str(computerdata["pc"]),
"color": "#0367D3"
},
{
"type": "text",
"text": "機房伺服器數量(台):"+str(computerdata["server"]),
"color": "#0367D3"
}
]
}
}
)
return flex_message
再來我們在views.py中新增,
if event.message.text == "機房資訊":
line_bot_api.reply_message( # 回復「機房資訊」按鈕輪播訊息
event.reply_token,
roomResourceslable().returna()
)
展示就大概如下!
撒花!!!我們把機房大概的功能都完成ㄌ~~
下一篇將做個總整理。
今天是 陳鈺羲 的 最愛 網址如下~~~